//
//  AddFunyPicCollectionViewCell.m
//  markmap
//
//  Created by 甘世清 on 2024/5/9.
//

#import "AddFunyPicCollectionViewCell.h"

@implementation AddFunyPicCollectionViewCell
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.layer.masksToBounds = YES;
        [self SQ_UIViewForSelfView];
    }
    return self;
}
/// 添加ui
-(void)SQ_UIViewForSelfView
{
    self.contentView.layer.cornerRadius = 20;
    self.contentView.clipsToBounds = YES;
    self.contentView.layer.masksToBounds = YES;
    self.contentView.backgroundColor = SQColor(@"#6B6B6B");
    [self.contentView addSubview:self.typeBtn];
    [self.typeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView);
    }];
    
    [self.contentView addSubview:self.bgImage];
    [self.bgImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView);
    }];
    
}
- (void)setModel:(AddModel *)model{
    _model = model;
    if (model.isAdd) {
        self.bgImage.hidden = YES;
        self.typeBtn.hidden = NO;
        self.typeBtn.text = [NSString stringWithFormat:@"%ld/9",(long)model.index];
    } else {
        self.bgImage.hidden = NO;
        self.typeBtn.hidden = YES;
        self.bgImage.image = model.addImage;
        if (model.url) {
            [self.bgImage sd_setImageWithURL:SQURLImage(model.url)];
        }
    }
}
- (UIImageView *)bgImage{
    if (!_bgImage) {
        _bgImage = [[UIImageView alloc]init];
        _bgImage.contentMode = UIViewContentModeScaleAspectFill;
        _bgImage.clipsToBounds = YES;
    }
    return _bgImage;
}
- (SQCustomButton *)typeBtn{
    if (!_typeBtn) {
        _typeBtn = [[SQCustomButton alloc]initType:SQCustomButtonTopImageType imageSize:CGSizeMake(24, 24) midmargin:4];
        _typeBtn.text = SQNSLocalString(@"0/9");
        _typeBtn.textColor = SQColor(@"#4A4A4A");
        _typeBtn.font = FONT_REGULAR(12);
        _typeBtn.image = SQGetImage(@"添加");
        _typeBtn.userInteractionEnabled = NO;
    }
    return _typeBtn;
}
@end
